package com.edu.framework.websocket.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.edu.framework.websocket.message.studyscore.StudyScoreVO;
import com.edu.system.service.ITStudyScoreService;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @program: xxxx
 * @description:
 * @author: zlh
 * @create: 2024-01-06 18:20
 **/
@Slf4j
@Component
public class StudyScoreService {

  @Resource
  private ITStudyScoreService itStudyScoreService;

  public List<StudyScoreVO> getScoreListVOS(Long studentId, String year, String month) {
    DateTime start = null;
    DateTime end = null;
    if (StrUtil.isNotBlank(year) && StrUtil.isBlank(month)){
      start = DateUtil.parseDate(year + "-01-01");
      end = DateUtil.parseDate(year + "-12-31");
    }
    if (StrUtil.isNotBlank(year) && StrUtil.isNotBlank(month)){
      start = DateUtil.parseDate(year + "-" + month + "-01");
      end = DateUtil.parseDate(year + "-" + month + "-31");
    }

    return itStudyScoreService.queryStudyScore(studentId, start, end)
        .stream()
        .map(a -> {
          StudyScoreVO studyScoreVO = BeanUtil.copyProperties(a, StudyScoreVO.class);
          studyScoreVO.setTotal(a.getScore());
          return studyScoreVO;
        })
        .collect(Collectors.toList());
  }

}
